package com.example.shoppingmall.cotroller;

import com.alibaba.fastjson.JSONArray;
import com.example.shoppingmall.config.PoiUtils;
import com.example.shoppingmall.pojo.*;
import com.example.shoppingmall.dao.*;
import com.example.shoppingmall.service.*;

import org.apache.ibatis.annotations.Param;
import org.apache.tomcat.util.http.fileupload.ParameterParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Controller
@RequestMapping("/commodity")
public class CommodityController {
    @Autowired
    private CommodityService commodityService;
    @Autowired
    private ClassifyService classifyService;
    @Autowired
    private TrademarkService trademarkService;
    @Autowired
    private MoldService moldService;
    @Autowired
    private Jurisdiction1Service jurisdiction1Service;
    @Autowired
    private ParameterService parameterService;
    @Autowired
    private Jurisdiction2Service jurisdiction2Service;
    @Autowired
    private PropertyService propertyService;
    @Autowired
    private ParameterJurisdictionService parameterJurisdictionService;
    @Autowired
    private PropertyJurisdictionService propertyJurisdictionService;
    @Autowired
    private EvaluateService evaluateService;
    @Autowired
    private ReplyService replyService;

    public void setReplyService(ReplyService replyService) {
        this.replyService = replyService;
    }

    public void setEvaluateService(EvaluateService evaluateService) {
        this.evaluateService = evaluateService;
    }

    public void setPropertyJurisdictionService(PropertyJurisdictionService propertyJurisdictionService) {
        this.propertyJurisdictionService = propertyJurisdictionService;
    }

    public void setParameterJurisdictionService(ParameterJurisdictionService parameterJurisdictionService) {
        this.parameterJurisdictionService = parameterJurisdictionService;
    }

    public void setPropertyService(PropertyService propertyService) {
        this.propertyService = propertyService;
    }

    public void setJurisdiction2Service(Jurisdiction2Service jurisdiction2Service) {
        this.jurisdiction2Service = jurisdiction2Service;
    }

    public void setParameterService(ParameterService parameterService) {
        this.parameterService = parameterService;
    }

    public void setJurisdiction1Service(Jurisdiction1Service jurisdiction1Service) {
        this.jurisdiction1Service = jurisdiction1Service;
    }

    public void setMoldService(MoldService moldService) {
        this.moldService = moldService;
    }

    public void setTrademarkService(TrademarkService trademarkService) {
        this.trademarkService = trademarkService;
    }

    public void setClassifyService(ClassifyService classifyService) {
        this.classifyService = classifyService;
    }

    public void setCommodityService(CommodityService commodityService) {
        this.commodityService = commodityService;
    }

    String names=null;
    String statuss=null;
    String repertorys=null;
    /**
     * 查询
     *
     * @param name
     * @param status
     * @param repertory
     * @param model
     * @param session
     * @return
     */
    @RequestMapping(value = "/toCommodityList")
    public String toCommodityList(
            @RequestParam(value = "name", required = false) String name,
            @RequestParam(value = "status", required = false) String status,
            @RequestParam(value = "repertory", required = false) String repertory,
            @RequestParam(value = "no", required = false) String no,
            Model model, HttpSession session) {

        int numAll = commodityService.countAll();
        int numUp = commodityService.countUp();
        int numDown = commodityService.countDown();
        int numRepertory = commodityService.countRepertory();

        if (status == null || status == "") {
            status = "0";
        }
        if (repertory == null || repertory == "") {
            repertory = "0";
        }
        if (status.equals("1")) {
            model.addAttribute("status", "1");
        }
        if (status.equals("2")) {
            model.addAttribute("status", "2");
        }
        if (repertory.equals("1")) {
            model.addAttribute("repertory", 1);
        }
        if(name!=null){
            names=name;
        }
        if(status!=null){
            statuss=status;
        }
        if(repertory!=null){
            repertorys=repertory;
        }
        int curr = 1;
        Page page = new Page();
        int count = commodityService.countList(names, Integer.parseInt(statuss), Integer.parseInt(repertorys));
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Commodity> commodityList = commodityService.commodityList(name, Integer.parseInt(status), Integer.parseInt(repertory)
                , (curr - 1) * 6);
        model.addAttribute("name", name);
        model.addAttribute("numAll", numAll);
        model.addAttribute("numUp", numUp);
        model.addAttribute("numDown", numDown);
        model.addAttribute("numRepertory", numRepertory);
        session.setAttribute("commodityList", commodityList);
        session.setAttribute("page", page);
        return "commodity/commodityList";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toCommodityDelete")
    public String toCommodityDelete(@RequestParam("id") String id) {
        int rs = commodityService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toCommodityList";
        } else {
            return "redirect:toCommodityList";
        }
    }

    /**
     * 根据父级id得到值
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/allname", produces = "application/json;charset=UTF-8")
    @ResponseBody
    public String allname(@RequestParam("id") int id) {
        List<Classify> allname = classifyService.classifyListByParentId(id);
        String json = JSONArray.toJSONString(allname);
        return json;
    }

    /**
     * 商品增加
     *
     * @param session
     * @return
     */
    @RequestMapping(value = "/toCommodityAdd")
    public String toMerchandiseAdd(HttpSession session) {
        List<Classify> classifyList = classifyService.classifyList();
        List<Mold>moldList=moldService.list();
        List<Trademark>trademarkList=trademarkService.list();
        session.setAttribute("classifyList", classifyList);
        session.setAttribute("moldList",moldList);
        session.setAttribute("trademarkList",trademarkList);
        return "commodity/commodityListAdd";
    }


    /**
     * 商品增加
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "CommodityAdd")
    public String CommodityAdd(
                               @Param("moldId") String moldId, @Param("trademarkId") String trademarkId,
                               @Param("name") String name, @Param("salesPrice") String salesPrice,
                               @Param("costPrice") String costPrice,@Param("classifyId") String classifyId,
                               @Param("marketPrice") String marketPrice, @Param("repertory") String repertory,
                                 MultipartFile files, HttpServletRequest request) {
        Commodity commodity=new Commodity();
        String path = ("F:\\shoppingmall\\src\\main\\resources\\static\\images");
        File file = new File(path);
        if (!file.isDirectory()) {
            file.mkdirs();
        }
        String oldname = files.getOriginalFilename();
        String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
        try {
            files.transferTo(new File(file, newname));
        } catch (IOException e) {
            e.printStackTrace();
        }
        commodity.setClassifyId(Integer.parseInt(classifyId));
        commodity.setMoldId(Integer.parseInt(moldId));
        commodity.setTrademarkId(Integer.parseInt(trademarkId));
        commodity.setName(name);
        commodity.setSalesPrice(Double.parseDouble(salesPrice));
        commodity.setCostPrice(Double.parseDouble(costPrice));
        commodity.setMarketPrice(Double.parseDouble(marketPrice));
        commodity.setRepertory(Integer.parseInt(repertory));
        commodity.setImgPath(newname);
        int rs = commodityService.add(commodity);
        if (rs > 0) {
            return "redirect:toCommodityList";
        } else {
            return "redirect:toCommodityList";
        }
    }

    /**
     * 判断商品名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackCommodityName")
    @ResponseBody
    public Object chackCommodityName(@RequestParam("name") String name) {
        int rs = commodityService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 查看商品详情
     * @param id
     * @param model
     * @return
     */
    @RequestMapping(value = "/toCommodityUpdate")
    public String toCommodityUpdate(@RequestParam("id")String id,Model model,HttpSession session){
        Commodity commodity=commodityService.xiangQing(Integer.parseInt(id));
        List<Mold>moldList=moldService.list();
        List<Trademark>trademarkList=trademarkService.list();
        List<Classify> classifyList = classifyService.classifyList();
        model.addAttribute("commodity",commodity);
        session.setAttribute("moldList",moldList);
        session.setAttribute("trademarkList",trademarkList);
        session.setAttribute("classifyList",classifyList);
        return "commodity/commodityUpdate";
    }

    /**
     * 商品修改操作
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "/CommodityUpdate")
    public String CommodityUpdate(
                                    @Param("id") String id,
                                    @Param("moldId") String moldId, @Param("trademarkId") String trademarkId,
                                    @Param("name") String name, @Param("salesPrice") String salesPrice,
                                    @Param("costPrice") String costPrice,@Param("classifyId") String classifyId,
                                    @Param("marketPrice") String marketPrice, @Param("repertory") String repertory,
                                    MultipartFile files, HttpServletRequest request) {
        Commodity commodity=new Commodity();
        if (!files.isEmpty()) {  //判断是否重新上传了图片
            String path = ("D:\\shoppingmall\\src\\main\\resources\\static\\images");
            File file = new File(path);
            if (!file.isDirectory()) {
                file.mkdirs();
            }
            String oldname = files.getOriginalFilename();
            String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
            try {
                files.transferTo(new File(file, newname));
            } catch (IOException e) {
                e.printStackTrace();
            }
            commodity.setClassifyId(Integer.parseInt(classifyId));
            commodity.setMoldId(Integer.parseInt(moldId));
            commodity.setTrademarkId(Integer.parseInt(trademarkId));
            commodity.setName(name);
            commodity.setSalesPrice(Double.parseDouble(salesPrice));
            commodity.setCostPrice(Double.parseDouble(costPrice));
            commodity.setMarketPrice(Double.parseDouble(marketPrice));
            commodity.setRepertory(Integer.parseInt(repertory));
            commodity.setImgPath(newname);
            commodity.setId(Integer.parseInt(id));
            int rs = commodityService.update(commodity);
            if (rs > 0) {
                return "redirect:toCommodityList";
            } else {
                return "redirect:toCommodityList";
            }
        } else {
            commodity.setClassifyId(Integer.parseInt(classifyId));
            commodity.setMoldId(Integer.parseInt(moldId));
            commodity.setTrademarkId(Integer.parseInt(trademarkId));
            commodity.setName(name);
            commodity.setSalesPrice(Double.parseDouble(salesPrice));
            commodity.setCostPrice(Double.parseDouble(costPrice));
            commodity.setMarketPrice(Double.parseDouble(marketPrice));
            commodity.setRepertory(Integer.parseInt(repertory));
            commodity.setId(Integer.parseInt(id));
            int rs = commodityService.update1(commodity);
            if (rs > 0) {
                return "redirect:toCommodityList";
            } else {
                return "redirect:toCommodityList";
            }

        }
    }

    /**
     * 商品评论查询
     * @param no
     * @param session
     * @return
     */
    @RequestMapping(value = "/toCommodityEvaluate")
    public String toCommodityEvaluate(
            @RequestParam(value = "commodityId", required = false) String commodityId,
            @RequestParam(value = "no", required = false) String no,
            HttpSession session) {
        int curr = 1;
        Page page = new Page();
        int count = evaluateService.countForCommodityId(Integer.parseInt(commodityId));
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Evaluate> evaluateList = evaluateService.listForCommodityId(Integer.parseInt(commodityId),(curr - 1) * 6);
        session.setAttribute("page", page);
        session.setAttribute("evaluateList", evaluateList);
        return "commodity/commodity_evaluate";
    }

    /**
     * 上架商品
     * @param id
     * @return
     */
    @RequestMapping(value = "/toCommodityUp")
    public String toCommodityUp(@RequestParam("id") String id) {
        int rs = commodityService.updateUp(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toCommodityList";
        } else {
            return "redirect:toCommodityList";
        }
    }

    /**
     * 下架商品
     * @param id
     * @return
     */
    @RequestMapping(value = "/toCommodityDown")
    public String toCommodityDowm(@RequestParam("id") String id) {
        int rs = commodityService.updateDown(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toCommodityList";
        } else {
            return "redirect:toCommodityList";
        }
    }

    //导出
    @RequestMapping(value = "/exportEmp", method = RequestMethod.GET)
    public ResponseEntity<byte[]> exportEmp() {
        return PoiUtils.exportEmp2Excel(commodityService.list());
    }

    //导入
    @RequestMapping(value = "/importEmp")
    public String importEmp(MultipartFile files) {
        List<Commodity> commodities = PoiUtils.importEmp2List(files);
        if (commodityService.addAll(commodities) == commodities.size()) {//受影响行数
            return "redirect:toCommodityList";
        }else{
            return "redirect:toCommodityList";
        }
    }

    /**
     * 查询品牌表
     *
     * @param name
     * @param updateTime
     * @param no
     * @param model
     * @return
     */
    @RequestMapping(value = "/toTradeTrademarkList")
    public String toTrademarkList(@RequestParam(value = "name", required = false) String name,
                                  @RequestParam(value = "updateTime", required = false) String updateTime,
                                  @RequestParam(value = "no", required = false) String no,
                                  Model model) {
        int curr = 1;
        Page page = new Page();
        int count = trademarkService.count(name, updateTime);
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Trademark> trademarkList = trademarkService.trademarkList(name, updateTime, (curr - 1) * 6);
        model.addAttribute("name", name);
        model.addAttribute("updateTime", updateTime);
        model.addAttribute("page", page);
        model.addAttribute("trademarkList", trademarkList);
        return "commodity/trademarkList";
    }

    /**
     * 品牌增加
     * @param name1
     * @param sorting
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "toTrademarkAdd")
    public String toTrademarkAdd(@Param("name1") String name1, @Param("sorting") String sorting,
                                 MultipartFile files, HttpServletRequest request) {
        Trademark trademark = new Trademark();
        String path = ("D:\\shoppingmall\\src\\main\\resources\\static\\images");
        File file = new File(path);
        if (!file.isDirectory()) {
            file.mkdirs();
        }
        String oldname = files.getOriginalFilename();
        String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
        try {
            files.transferTo(new File(file, newname));
        } catch (IOException e) {
            e.printStackTrace();
        }
        trademark.setName(name1);
        trademark.setLOGO(newname);
        trademark.setSorting(Integer.parseInt(sorting));
        int rs = trademarkService.add(trademark);
        if (rs > 0) {
            return "redirect:toTradeTrademarkList";
        } else {
            return "redirect:toTradeTrademarkList";
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toTrademarkDelete")
    public String toTrademarkDelete(@RequestParam("id") String id) {
        int rs = trademarkService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toTradeTrademarkList";
        } else {
            return "redirect:toTradeTrademarkList";
        }
    }

    /**
     * 判断品牌名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackTradeMarkName")
    @ResponseBody
    public Object chackUserPhone(@RequestParam("name") String name) {
        int rs = trademarkService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 跳到品牌修改页面
     *
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toTradeMarkXiangQing")
    public String toTradeMarkXiangQing(@RequestParam("id") String id, HttpSession session) {
        Trademark trademark = trademarkService.xiangQing(Integer.parseInt(id));
        session.setAttribute("trademark", trademark);
        return "commodity/trademarkListUpdate";
    }

    /**
     * 修改操作
     *
     * @param name
     * @param sorting
     * @param id
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "/toTradeMarkUpdate")
    public String toTradeMarkUpdate(@Param("name") String name, @Param("sorting") String sorting, @Param("id") String id,
                                    @Param("LOGO") String LOGO,
                                    MultipartFile files, HttpServletRequest request) {
        Trademark trademark = new Trademark();
        if (!files.isEmpty()) {  //判断是否重新上传了图片
            String path = ("D:\\shoppingmall\\src\\main\\resources\\static\\images");
            File file = new File(path);
            if (!file.isDirectory()) {
                file.mkdirs();
            }
            String oldname = files.getOriginalFilename();
            String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
            try {
                files.transferTo(new File(file, newname));
            } catch (IOException e) {
                e.printStackTrace();
            }
            trademark.setId(Integer.parseInt(id));
            trademark.setName(name);
            trademark.setLOGO(newname);
            trademark.setSorting(Integer.parseInt(sorting));
            int rs = trademarkService.update(trademark);
            if (rs > 0) {
                return "redirect:toTradeTrademarkList";
            } else {
                return "redirect:toTradeTrademarkList";
            }
        } else {
            trademark.setId(Integer.parseInt(id));
            trademark.setName(name);
            trademark.setLOGO(LOGO);
            trademark.setSorting(Integer.parseInt(sorting));
            int rs = trademarkService.update(trademark);
            if (rs > 0) {
                return "redirect:toTradeTrademarkList";
            } else {
                return "redirect:toTradeTrademarkList";
            }

        }
    }

    /**
     * 商品类型查询
     * @param session
     * @return
     */
    @RequestMapping(value = "/toMoldList")
    public String toMoldList(HttpSession session,@RequestParam(value = "no",required = false)String no){
        int curr = 1;
        Page page = new Page();
        int count = moldService.count();
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Mold>moldList=moldService.moldList((curr-1)*6);
        session.setAttribute("moldList",moldList);
        session.setAttribute("page",page);
        return "commodity/moldList";
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toMoldDelete")
    public String toMoldDelete(@RequestParam("id") String id) {
        int rs = moldService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toMoldList";
        } else {
            return "redirect:toMoldList";
        }
    }

    /**
     * 查看属性
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toMoldParameterList")
    public String toMoldParameterList(@RequestParam("id")String id,HttpSession session){
        Mold mold=moldService.xiangQing(Integer.parseInt(id));
        List<Jurisdiction1>jurisdiction1List=jurisdiction1Service.jurisdiction1List(Integer.parseInt(id));
        session.setAttribute("mold",mold);
        session.setAttribute("jurisdiction1List",jurisdiction1List);
        return "commodity/moldParameterList";
    }

    /**
     * 跳转至增加属性页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toMoldParameterListAdd")
    public String toMoldParameterListAdd(@RequestParam("id")Integer id, HttpSession session){
        List<Parameter>parameterList=parameterService.parameterList();
        session.setAttribute("parameterList",parameterList);
        session.setAttribute("moldId",id);
        return "commodity/moldParameterListAdd";
    }


    /**
     * 增加操作
     * @param moldId
     * @param parameterId
     * @return
     */
    @RequestMapping(value = "/moldParameterListAdd")
    public String moldParameterListAdd(@RequestParam("moldId")String moldId,@RequestParam("parameterId")String parameterId,
                                       Model model){
       int rs=jurisdiction1Service.chack(Integer.parseInt(moldId),Integer.parseInt(parameterId));
        if(rs>0){
            model.addAttribute("error","该属性此类型已拥有!");
            return "commodity/moldParameterListAdd";
        }else {
            Jurisdiction1 jurisdiction1=new Jurisdiction1();
            jurisdiction1.setMoldId(Integer.parseInt(moldId));
            jurisdiction1.setParameterId(Integer.parseInt(parameterId));
            int rs1 = jurisdiction1Service.add(jurisdiction1);
            if (rs1 > 0) {
                return "redirect:toMoldList";
            } else {
                return "redirect:toMoldList";
            }
        }
    }
    /**
     * 属性删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/moldParameterListDelete")
    public String moldParameterListDelete(@RequestParam("id")String id){
        int rs=jurisdiction1Service.delete(Integer.parseInt(id));
        if(rs>0){
            return "redirect:toMoldList";
        }else{
            return "redirect:toMoldList";
        }
    }

    /**
     * 查看参数
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toMoldPropertyList",produces="text/plain;charset=UTF-8")
    public String toMoldPropertyList(@RequestParam("id")String id,HttpSession session){
        Mold mold=moldService.xiangQing(Integer.parseInt(id));
        List<Jurisdiction2>jurisdiction2List=jurisdiction2Service.jurisdiction2List(Integer.parseInt(id));
        session.setAttribute("mold",mold);
        session.setAttribute("jurisdiction2List",jurisdiction2List);
        return "commodity/moldPropertyList";
    }

   /**
     * 跳转至增加参数页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toMoldPropertyListAdd")
    public String toMoldPropertyListAdd(@RequestParam("id")Integer id, HttpSession session){
        List<Property>propertyList=propertyService.propertyList();
        session.setAttribute("propertyList",propertyList);
        session.setAttribute("moldId",id);
        return "commodity/moldPropertyListAdd";
    }


    /**
     * 增加操作
     * @param moldId
     * @param propertyId
     * @return
     */
    @RequestMapping(value = "/moldPropertyListAdd")
    public String moldPropertyListAdd(@RequestParam("moldId")String moldId,@RequestParam("propertyId")String propertyId,
                                       Model model){
        int rs=jurisdiction2Service.chack(Integer.parseInt(moldId),Integer.parseInt(propertyId));
        if(rs>0){
            model.addAttribute("error","该属性此类型已拥有!");
            return "commodity/moldPropertyListAdd";
        }else {
            Jurisdiction2 jurisdiction2=new Jurisdiction2();
            jurisdiction2.setMoldId(Integer.parseInt(moldId));
            jurisdiction2.setPropertyId(Integer.parseInt(propertyId));
            int rs1 = jurisdiction2Service.add(jurisdiction2);
            if (rs1 > 0) {
                return "redirect:toMoldList";
            } else {
                return "redirect:toMoldList";
            }
        }
    }
    /**
     * 属性删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/moldPropertyListDelete")
    public String moldPropertyListDelete(@RequestParam("id")String id){
        int rs=jurisdiction2Service.delete(Integer.parseInt(id));
        if(rs>0){
            return "redirect:toMoldList";
        }else{
            return "redirect:toMoldList";
        }
    }

    /**
     * 类型新增
     * @param name1
     * @return
     */
    @RequestMapping(value = "/toMoldListAdd")
    public String toMoldListAdd(@Param("name1")String name1){
        int rs=moldService.add(name1);
        if(rs>0){
            return "redirect:toMoldList";
        }else{
            return "redirect:toMoldList";
        }
    }

    /**
     * 判断类型名是否存在
     *
     * @param name1
     * @return
     */
    @RequestMapping(value = "/toMoldListChack")
    @ResponseBody
    public Object toMoldListChack(@RequestParam("name1") String name1) {
        int rs = moldService.chack(name1);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 去MoldUpdate页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "toMoldListUpdate")
    public String toMoldListUpdate(@RequestParam("id")String id,HttpSession session){
        Mold mold=moldService.xiangQing(Integer.parseInt(id));
        session.setAttribute("mold",mold);
        return "commodity/moldListUpdate";
    }

    /**
     * 修改mold信息
     * @param id
     * @param name
     * @return
     */
    @RequestMapping(value = "MoldListUpdate")
    public String MoldListUpdate(@RequestParam("id")String id,@RequestParam("name")String name){
        Mold mold=new Mold();
        mold.setId(Integer.parseInt(id));
        mold.setName(name);
        int rs=moldService.update(mold);
        if(rs>0){
            return "redirect:toMoldList";
        }else{
            return "redirect:toMoldList";
        }
    }

    /**
     * 商品属性列表
     * @param session
     * @param no
     * @return
     */
    @RequestMapping(value = "/toParameterList")
    public String toParameterList(HttpSession session,@RequestParam(value = "no",required = false)String no){
        int curr = 1;
        Page page = new Page();
        int count = parameterService.count();
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Parameter>parameterList=parameterService.parameterListForNo((curr-1)*6);
        session.setAttribute("parameterList",parameterList);
        session.setAttribute("page",page);
        return "commodity/parameterList";
    }

    /**
     * 查看属性值
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toParameterListValue")
    public String toParameterListValue(@RequestParam("id")String id,HttpSession session){
        List<ParameterJurisdiction>parameterJurisdictions=parameterJurisdictionService.parameterJurisdictionList(Integer.parseInt(id));
        Parameter parameter=parameterService.xiangQing(Integer.parseInt(id));
        session.setAttribute("parameter",parameter);
        session.setAttribute("parameterJurisdictions",parameterJurisdictions);
        return "commodity/parameterListValue";
    }

    /**
     * 增加属性值
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toParameterListValueAdd")
    public String toParameterListValueAdd(@RequestParam("id")String id,HttpSession session){
        Parameter parameter=parameterService.xiangQing(Integer.parseInt(id));
        session.setAttribute("parameter",parameter);
        return "commodity/parameterListValueAdd";
    }

    /**
     * 增加属性值
     * @param parameterId
     * @param name
     * @return
     */
    @RequestMapping(value = "/parameterListValueAdd")
    public String parameterListValueAdd(@RequestParam("parameterId")String parameterId,
                                        @RequestParam("name")String name){
        ParameterJurisdiction parameterJurisdiction=new ParameterJurisdiction();
        parameterJurisdiction.setParameterId(Integer.parseInt(parameterId));
        parameterJurisdiction.setName(name);
        int rs=parameterJurisdictionService.add(parameterJurisdiction);
        if(rs>0){
            return "redirect:toParameterList";
        }else{
            return "redirect:toParameterList";
        }
    }

    /**
     * 判断属性值
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackParameterJName")
    @ResponseBody
    public Object chackParameterJName(@RequestParam("name") String name,@Param("id")String id) {
        int rs = parameterJurisdictionService.chackName(name,Integer.parseInt(id));
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }
    /**
     * 删除属性
     * @param id
     * @return
     */
    @RequestMapping(value = "/toParameterJDelete")
    public String toParameterJDelete(@RequestParam("id") String id) {
        int rs = parameterJurisdictionService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toParameterList";
        } else {
            return "redirect:toParameterList";
        }
    }

    /**
     * 属性删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toParameterDelete")
    public String toParameterDelete(@Param("id")String id){
        int rs=parameterService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toParameterList";
        } else {
            return "redirect:toParameterList";
        }
    }

    /**
     * 增加
     * @param name1
     * @param model
     * @return
     */
    @RequestMapping(value = "/toParameterAdd")
    public String toParameterAdd(@RequestParam("name1")String name1,Model model){
        int rs=parameterService.add(name1);
        if (rs > 0) {
            return "redirect:toParameterList";
        } else {
            return "redirect:toParameterList";
        }
    }

    /**
     * 判断属性名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackParameterName")
    @ResponseBody
    public Object chackParameterName(@RequestParam("name") String name) {
        int rs = parameterService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 到属性修改页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toParametetUpdate")
    public String toParametetUpdate(@RequestParam("id")String id,HttpSession session){
        Parameter parameter=parameterService.xiangQing(Integer.parseInt(id));
        session.setAttribute("parameter",parameter);
        return "commodity/parameterListUpdate";
    }

    /**
     * 修改parameter信息
     * @param id
     * @param name
     * @return
     */
    @RequestMapping(value = "ParameterUpdate")
    public String ParameterUpdate(@RequestParam("id")String id,@RequestParam("name")String name){
        Parameter parameter=new Parameter();
        parameter.setId(Integer.parseInt(id));
        parameter.setName(name);
        int rs=parameterService.update(parameter);
        if(rs>0){
            return "redirect:toParameterList";
        }else{
            return "redirect:toParameterList";
        }
    }

    /**
     * 去参数列表
     * @param session
     * @return
     */
    @RequestMapping(value = "/toPropertyList")
    public String toPropertyList(HttpSession session,@RequestParam(value = "no",required = false)String no){
        int curr = 1;
        Page page = new Page();
        int count = propertyService.count();
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Property>propertyList=propertyService.propertyListForNo((curr-1)*6);
        session.setAttribute("propertyList",propertyList);
        session.setAttribute("page",page);
        return "commodity/propertyList";
    }

    /**
     * 去参数值页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toPropertyListValue")
    public String toPropertyListValue(@RequestParam("id")String id,HttpSession session){
        Property property=propertyService.xiangQing(Integer.parseInt(id));
        session.setAttribute("property",property);
        List<PropertyJurisdiction>propertyJurisdictionList=
                propertyJurisdictionService.propertyJurisdictionListByPropertyId(Integer.parseInt(id));
        session.setAttribute("propertyJurisdictionList",propertyJurisdictionList);
        return "commodity/propertyListValue";



    }

    /**
     * 参数删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toPropertyDelete")
    public String toPropertyDelete(@RequestParam("id") String id) {
        int rs = propertyService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toPropertyList";
        } else {
            return "redirect:toPropertyList";
        }
    }
    /**
     * 参数值删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toPropertyJDelete")
    public String toPropertyJDelete(@RequestParam("id") String id) {
        int rs = propertyJurisdictionService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toPropertyList";
        } else {
            return "redirect:toPropertyList";
        }
    }
    /**
     * 去增加参数值
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toPropertyListValueAdd")
    public String toPropertyListValueAdd(@RequestParam("id")String id,HttpSession session){
        Property property=propertyService.xiangQing(Integer.parseInt(id));
        session.setAttribute("property",property);
        return "commodity/propertyListValueAdd";
    }
    /**
     * 增加参数值
     * @param propertyId
     * @param name
     * @return
     */
    @RequestMapping(value = "/propertyListValueAdd")
    public String propertyListValueAdd(@RequestParam("propertyId")String propertyId,
                                        @RequestParam("name")String name){
        PropertyJurisdiction propertyJurisdiction=new PropertyJurisdiction();
        propertyJurisdiction.setPropertyId(Integer.parseInt(propertyId));
        propertyJurisdiction.setName(name);
        int rs=propertyJurisdictionService.add(propertyJurisdiction);
        if(rs>0){
            return "redirect:toPropertyList";
        }else{
            return "redirect:toPropertyList";
        }
    }
    /**
     * 判断参数值是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackPropertyJName")
    @ResponseBody
    public Object chackPropertyJName(@RequestParam("name") String name,@RequestParam("id") String id) {
        int rs = propertyJurisdictionService.chackName(name,Integer.parseInt(id));
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 参数增加
     * @param name1
     * @param typeId
     * @return
     */
    @RequestMapping(value = "/propertyListAdd")
    public String propertyListAdd(@RequestParam("name1")String name1,@RequestParam("typeId")String typeId){
        Property property=new Property();
        property.setName(name1);
        property.setTypeId(Integer.parseInt(typeId));
        int rs=propertyService.add(property);
        if(rs>0){
            return "redirect:toPropertyList";
        }else{
            return "redirect:toPropertyList";
        }
    }
    /**
     * 参数删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toPropertyListDelete")
    public String toPropertyListDelete(@RequestParam("id") String id) {
        int rs = propertyService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toPropertyList";
        } else {
            return "redirect:toPropertyList";
        }
    }
    /**
     * 判断品牌名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackPropertyListName")
    @ResponseBody
    public Object chackPropertyListName(@RequestParam("name") String name) {
        int rs = propertyService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 到参数修改页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toPropertyUpdate")
    public String toPropertyUpdate(@RequestParam("id")String id,HttpSession session){
        Property property=propertyService.xiangQing(Integer.parseInt(id));
        session.setAttribute("property",property);
        return "commodity/propertyListUpdate";
    }

    /**
     * 修改property信息
     * @param id
     * @param name
     * @return
     */
    @RequestMapping(value = "propertyUpdate")
    public String propertyUpdate(@RequestParam("id")String id,@RequestParam("name")String name,
        @RequestParam("typeId")String typeId){
        Property property=new Property();
        property.setId(Integer.parseInt(id));
        property.setName(name);
        property.setTypeId(Integer.parseInt(typeId));
        int rs=propertyService.update(property);
        if(rs>0){
            return "redirect:toPropertyList";
        }else{
            return "redirect:toPropertyList";
        }
    }
    /**
     * 判断品牌名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackPropertyName")
    @ResponseBody
    public Object chackPropertyName(@RequestParam("name") String name) {
        int rs = propertyService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 评价
     * @param userPhone
     * @param orderno
     * @param no
     * @param session
     * @param model
     * @return
     */
    @RequestMapping(value = "/toEvaluateList")
    public String toEvaluateList(@RequestParam(value = "userPhone",required = false)String userPhone,
                                 @RequestParam(value = "orderno",required = false)String orderno,
                                 @RequestParam(value = "no",required = false)String no,
                                 HttpSession session,Model model){
        int curr = 1;
        Page page = new Page();
        int count = evaluateService.count(userPhone,orderno);
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Evaluate>evaluateList=evaluateService.evaluateList(userPhone,orderno,(curr-1)*6);
        session.setAttribute("evaluateList",evaluateList);
        session.setAttribute("page",page);
        model.addAttribute("userPhone",userPhone);
        model.addAttribute("orderno",orderno);
        return "commodity/evaluateList";
    }

    /**
     * 商家回复
     * @param orderno
     * @param session
     * @return
     */
    @RequestMapping(value = "/toEvaluateReply")
    public String toEvaluateReply(@RequestParam("orderno")String orderno,HttpSession session){
        Evaluate evaluate=evaluateService.xiangQing(orderno);
        session.setAttribute("evaluate",evaluate);
        return "commodity/evaluateReply";
    }

    /**
     * 回复操作
     * @param evaluateId
     * @param content
     * @return
     */
    @RequestMapping(value = "/toReply")
    public String toReply(@RequestParam("evaluateId")String evaluateId,@RequestParam("content")String content,
                               @RequestParam("orderno")String orderno){
        Reply reply=new Reply();
        reply.setOrderno(orderno);
        reply.setContent(content);
        int rs=replyService.add(reply);
        if(rs>0){
            evaluateService.update(Integer.parseInt(evaluateId));
            return "redirect:toEvaluateList";
        }else{
            return "redirect:toEvaluateList";
        }
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/evaluateListDelete")
    public String evaluateListDelete(@RequestParam("id") String id) {
        int rs = evaluateService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toEvaluateList";
        } else {
            return "redirect:toEvaluateList";
        }
    }

    @RequestMapping(value = "/evaluateReplyXiangQing")
    public String evaluateReplyXiangQing(@Param("orderno")String orderno,HttpSession session){
        Evaluate evaluate=evaluateService.xiangQing(orderno);
        Reply reply=replyService.xiangQing(orderno);
        session.setAttribute("evaluate",evaluate);
        session.setAttribute("reply",reply);
        return "commodity/evaluateReplyXiangQing";
    }

    /**
     * 商品分类列表
     * @return
     */
    @RequestMapping(value = "/toClassifyList")
    public String toClassifyList(
            @RequestParam(value = "no",required = false)String no,
            Model model){
        int curr = 1;
        Page page = new Page();
        int count = classifyService.count();
        page.setCount(count);
        if (no != null) {
            curr = Integer.parseInt(no);
            if (curr > page.getPageSum()) {
                curr = page.getPageSum();
            } else if (curr < 1) {
                curr = 1;
            }
        }
        page.setPageNo(curr);
        List<Classify>classifyListByOne=classifyService.getClassifyByOne();
        List<Classify>classifyList=classifyService.getClassifyList((curr-1)*6);
        List<Mold>moldList=moldService.list();
        model.addAttribute("classifyListByOne",classifyListByOne);
        model.addAttribute("classifyList",classifyList);
        model.addAttribute("moldList",moldList);
        model.addAttribute("page",page);
        return "commodity/classifyList";
    }

    /**
     * 商品分类新增
     * @param parentId
     * @param moldId
     * @param name
     * @param sorting
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "/toClassifyAdd")
    public String toClassifyAdd(@RequestParam("parentId")String parentId,@RequestParam("moldId")String moldId,
                                @RequestParam("name")String name,@RequestParam("sorting")String sorting,
                                MultipartFile files, HttpServletRequest request) {
        Classify classify = new Classify();
        String path = ("F:\\shoppingmall\\src\\main\\resources\\static\\images");
        File file = new File(path);
        if (!file.isDirectory()) {
            file.mkdirs();
        }
        String oldname = files.getOriginalFilename();
        String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
        try {
            files.transferTo(new File(file, newname));
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (parentId.equals("-1")) { //顶级分类
            classify.setLOGO(newname);
            classify.setMoldId(Integer.parseInt(moldId));
            classify.setName(name);
            classify.setSorting(Integer.parseInt(sorting));
            int rs = classifyService.add1(classify);
            if (rs > 0) {
                return "redirect:toClassifyList";
            } else {
                return "redirect:toClassifyList";
            }
        } else {
            classify.setLOGO(newname);
            classify.setMoldId(Integer.parseInt(moldId));
            classify.setParentId(Integer.parseInt(parentId));
            classify.setName(name);
            classify.setSorting(Integer.parseInt(sorting));
            int rs = classifyService.add(classify);
            if (rs > 0) {
                return "redirect:toClassifyList";
            } else {
                return "redirect:toClassifyList";
            }
        }
    }

    /**
     * 判断商品分类名是否存在
     * @param name
     * @return
     */
    @RequestMapping(value = "/chackClassifyName")
    @ResponseBody
    public Object chackClassifyName(@RequestParam("name") String name) {
        int rs = classifyService.chackName(name);
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 商品分类删除
     * @param id
     * @return
     */
    @RequestMapping(value = "/toClassifyDelete")
    public String toClassifyDelete(@RequestParam("id") String id) {
        int rs = classifyService.delete(Integer.parseInt(id));
        if (rs > 0) {
            return "redirect:toClassifyList";
        } else {
            return "redirect:toClassifyList";
        }
    }

    /**
     * 判断该parentId是否有二级分类
     * @param parentId
     * @return
     */
    @RequestMapping(value = "/chackParentId")
    @ResponseBody
    public Object chackParentId(@RequestParam("parentId") String parentId) {
        int rs = classifyService.chackParentId(Integer.parseInt(parentId));
        Map<Object, Object> map = new HashMap<Object, Object>();
        if (rs > 0) {
            map.put("checking", "exists");
        } else {
            map.put("checking", "no");
        }
        return JSONArray.toJSONString(map);
    }

    /**
     * 跳转到新增页面
     * @param id
     * @param session
     * @return
     */
    @RequestMapping(value = "/toClassifyAddYM")
    public String toClassifyAddYM(@RequestParam("id")String id,HttpSession session){
        Classify classify=classifyService.xiangQing(Integer.parseInt(id));
        List<Mold>moldList=moldService.list();
        session.setAttribute("classify",classify);
        session.setAttribute("moldList",moldList);
        return "commodity/classifyListAdd";
    }

    /**
     * 去修改页面
     * @param id
     * @param model
     * @param session
     * @return
     */
    @RequestMapping(value = "/toClassifyUpdate")
    public String toClassifyUpdate(@RequestParam("id")String id,Model model,HttpSession session){
        Classify classify=classifyService.xiangQing(Integer.parseInt(id));
        List<Mold>moldList=moldService.list();
        List<Classify>classifyListByOne=classifyService.getClassifyByOne();
        session.setAttribute("moldList",moldList);
        session.setAttribute("classifyListByOne",classifyListByOne);
        model.addAttribute("classify",classify);
        return "commodity/classifyListUpdate";
    }

    /**
     * 分类信息修改
     * @param id
     * @param parentId
     * @param moldId
     * @param name
     * @param sorting
     * @param files
     * @param request
     * @return
     */
    @RequestMapping(value = "/classifyUpdate")
    public String classifyUpdate(
                                 @RequestParam("id")String id,
                                 @RequestParam("parentId")String parentId,@RequestParam("moldId")String moldId,
                                 @RequestParam("name")String name,@RequestParam("sorting")String sorting,
                                 MultipartFile files, HttpServletRequest request){
        Classify classify = new Classify();
        if (!files.isEmpty()) {  //判断是否重新上传了图片
            String path = ("C:\\Users\\Administrator\\Desktop\\shoppingmall1\\src\\main\\resources\\static\\images\\");
            File file = new File(path);
            if (!file.isDirectory()) {
                file.mkdirs();
            }
            String oldname = files.getOriginalFilename();
            String newname = UUID.randomUUID().toString() + oldname.substring(oldname.lastIndexOf("."), oldname.length());
            try {
                files.transferTo(new File(file, newname));
            } catch (IOException e) {
                e.printStackTrace();
            }
            if(parentId.equals("0")){  //重新上传了图片  未改变了父级
                classify.setId(Integer.parseInt(id));
                classify.setLOGO(newname);
                classify.setMoldId(Integer.parseInt(moldId));
                classify.setName(name);
                classify.setSorting(Integer.parseInt(sorting));
                int rs=classifyService.update2(classify);
                if (rs > 0) {
                    return "redirect:toClassifyList";
                } else {
                    return "redirect:toClassifyList";
                }
            }else{  //重新上传了图片  未改变父级
                classify.setId(Integer.parseInt(id));
                classify.setLOGO(newname);
                classify.setParentId(Integer.parseInt(parentId));
                classify.setMoldId(Integer.parseInt(moldId));
                classify.setName(name);
                classify.setSorting(Integer.parseInt(sorting));
                int rs=classifyService.update1(classify);
                if (rs > 0) {
                    return "redirect:toClassifyList";
                } else {
                    return "redirect:toClassifyList";
                }
            }
        }else{
            if(parentId.equals("")|| parentId.equals("-1")){ //未重新上传了图片  未改变了父级
                classify.setId(Integer.parseInt(id));
                classify.setMoldId(Integer.parseInt(moldId));
                classify.setName(name);
                classify.setSorting(Integer.parseInt(sorting));
                int rs=classifyService.update4(classify);
                if (rs > 0) {
                    return "redirect:toClassifyList";
                } else {
                    return "redirect:toClassifyList";
                }
            }else{ //未重新上传了图片  改变了父级
                classify.setId(Integer.parseInt(id));
                classify.setMoldId(Integer.parseInt(moldId));
                classify.setParentId(Integer.parseInt(parentId));
                classify.setName(name);
                classify.setSorting(Integer.parseInt(sorting));
                int rs=classifyService.update3(classify);
                if (rs > 0) {
                    return "redirect:toClassifyList";
                } else {
                    return "redirect:toClassifyList";
                }
            }
        }
    }
}